package 第二讲数据结构;

import java.util.Scanner;

public class AcWing829 {
	static int N=100010;
	static int[] queue=new int[N];
	public static void main(String[] args) {
		int tt=-1;
		int hh=0;
		Scanner sc=new Scanner(System.in);
		int m=sc.nextInt();
		while(m-->0) {
			String opt = sc.next();
			if("push".equals(opt)) {
				int x=sc.nextInt();
				queue[++tt]=x;
			}else if("pop".equals(opt)) {
				hh++;
			}else if("empty".equals(opt)) {
				System.out.println(tt>=hh?"NO":"YES");
			}else if("query".equals(opt)) {
				System.out.println(queue[hh]);
			}
		}
		sc.close();
	}

}
